package com.cs410.collabwriting.connectors;

import java.util.HashMap;

import com.cs410.collabwriting.main.User;

public class SessionManager {

	private static HashMap< Integer, User> s_sessionMap = new HashMap<Integer,User>();
	
	private SessionManager(){;}

	public static User getUserIDForJSessionID( String id ) {
		if( id != null  && s_sessionMap.get( id.hashCode() ) != null) {
			User user = (User) s_sessionMap.get( id.hashCode() );
			if( user.isActive() ) {
				return user;
			}
			removeJSessionUserIDPair( id );
			return null;
		}
		return null;
	}
	
	public static User getUserIDForJSessionIDNoActivity( String id ) {
		if( id != null  && s_sessionMap.get( id.hashCode() ) != null) {
			User user = (User) s_sessionMap.get( id.hashCode() );
			return user;
		}
		return null;
	}
	
	public static void addJSessionUserIDPair( String id, User user ) {
		s_sessionMap.put( id.hashCode(), user );
	}
	
	public static void removeJSessionUserIDPair( String id ) {
		s_sessionMap.remove( id.hashCode() );
	}
	
}
